home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Demos / C Demos / Button / Movable.c < prev   
Text File  |  1995-03-21  |  2KB  |  110 lines

  1. /*
  2.  * The stuff in this file presents a movable modal dialog with an outlined
  3.  * pushbutton.  It demonstrates:
  4.  * - Movable modal dialog handling.
  5.  * - Button outlining in a movable modal dialog.
  6.  *
  7.  * Clicks in either the Cancel or OK buttons dismiss the dialog.
  8.  */
  9.  
  10. # include    "TransSkel.h"
  11.  
  12. # include    "Button.h"
  13.  
  14.  
  15. typedef enum
  16. {
  17.     okBtn = 1,
  18.     cancelBtn
  19. };
  20.  
  21.  
  22. static DialogPtr    dlog = (DialogPtr) nil;
  23.  
  24.  
  25. /*
  26.  * This filter must react to deactivates, not just activates, because the
  27.  * application can be put in the background while the movable modal dialog
  28.  * is in front.
  29.  */
  30.  
  31. static pascal Boolean
  32. Filter (DialogPtr dlog, EventRecord *evt, short *item)
  33. {
  34. Boolean    result = false;
  35. short    hilite;
  36.  
  37.     switch (evt->what)
  38.     {
  39.     case updateEvt:
  40.         SkelDrawButtonOutline (SkelGetDlogCtl (dlog, okBtn));
  41.         break;
  42.     case activateEvt:
  43.         hilite = ((evt->modifiers & activeFlag) ? normalHilite : dimHilite);
  44.         (void) SkelSetDlogCtlHilite (dlog, okBtn, hilite);
  45.         SkelDrawButtonOutline (SkelGetDlogCtl (dlog, okBtn));
  46.         (void) SkelSetDlogCtlHilite (dlog, cancelBtn, hilite);
  47.         break;
  48.     case keyDown:
  49.         result = SkelDlogMapKeyToButton (dlog, evt, item, okBtn, cancelBtn);
  50.         break;
  51.     }
  52.     return (result);
  53. }
  54.  
  55.  
  56. static pascal void
  57. Select (DialogPtr dlog, short item)
  58. {
  59.     switch (item)
  60.     {
  61.     case okBtn:
  62.     case cancelBtn:
  63.         HideWindow (dlog);
  64.         AdjustMenus ();
  65.         break;
  66.     }
  67. }
  68.  
  69.  
  70. static pascal void
  71. Clobber (void)
  72. {
  73. DialogPtr    dlog;
  74.  
  75.     GetPort (&dlog);
  76.     HideWindow (dlog);
  77.     DisposeDialog (dlog);
  78. }
  79.  
  80.  
  81. /*
  82.  * Present movable modal dialog
  83.  */
  84.  
  85. void
  86. DoMovableModal (void)
  87. {
  88.     if (dlog != (DialogPtr) nil)
  89.     {
  90.         SelectWindow (dlog);
  91.         ShowWindow (dlog);
  92.         AdjustMenus ();
  93.         return;
  94.     }
  95.     dlog = GetNewDialog (movableRes, nil, (WindowPtr) -1L);
  96.     if (dlog == (DialogPtr) nil)
  97.     {
  98.         SysBeep (1);
  99.         return;
  100.     }
  101.     SkelPositionWindow (dlog, skelPositionOnMainDevice, horizRatio, vertRatio);
  102.     SkelDialog (dlog,
  103.                 Filter,
  104.                 Select,
  105.                 nil,            /* no close box, so no close handler */
  106.                 Clobber);
  107.     ShowWindow (dlog);
  108.     AdjustMenus ();
  109. }
  110.